package org.example.Example;

import org.example.Main;
import org.example.Sort.MargeSort;

import java.util.Arrays;
/**
 * 荷兰国旗问题，分三份
 * */
public class Marge {
    public void sort(int[] arr,int target){
       int left=0;
       int right = arr.length-1;
       int i = 0;
       while(i<=right){
           if(arr[i]<target&&left<right){
                swap(arr,left++,i++);
           }
           else if(arr[i]>target){
               swap(arr,i++,right--);
           }
           else
           i++;
       }

    }
    public void swap(int arr[],int L,int R){
        int i = arr[L];
        arr[L] = arr[R];
        arr[R] = i;
    }
    public static void main(String[] args) {
        int arr[] = {3,5,6,3,4,5,2,6,9,0};
        new Marge().sort(arr,5);
        Arrays.stream(arr).forEach(System.out::print);
    }
}
